<?php

function b2_add_product_hunt_post_fields()
{
	//product type meta box
    $product_hunt_post_meta = new_cmb2_box(array(
        'id'            => 'single_producthunt',
        'title'         => __( '产品设置', 'b2' ),
        'object_types'  => array( 'producthunt'),
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true,
    ));

    $seo_meta_box = new_cmb2_box(array(
        'id'            => 'product_hunt_seo_side_metabox',
        'title'         => __( 'SEO设置', 'b2' ),
        'object_types'  => array('producthunt'), // Post type
        'context'       => 'side',
        'priority'      => 'high',
        'show_names'    => true,
    ));

    $seo_meta_box->add_field(array(
        'name' => __('SEO标题','b2'),
        'id'   => 'producthunt_seo_title',
        'type' => 'text',
        'default'=>'',
    ));

    $seo_meta_box->add_field(array(
        'name' => __('SEO关键词','b2'),
        'id'   => 'producthunt_seo_keywords',
        'type' => 'text',
        'default'=>'',
    ));

    $seo_meta_box->add_field(array(
        'name' => __('SEO描述','b2'),
        'id'   => 'producthunt_seo_description',
        'type' => 'textarea_small',
        'default'=>'',
    ));

    //product short description
    $product_hunt_post_meta->add_field(array(
        'name' => '产品简短简介',
        'id'   => 'product_short_description',
        'type' => 'textarea_small',
    ));


    //product logo
    $product_hunt_post_meta->add_field(array(
        'name' => '产品LOGO',
        'id'   => 'product_logo',
        'type' => 'file',
    ));

    $product_hunt_post_meta->add_field(array(
        'name' => '是否推荐',
        'id'   => 'featured',
        'type' => 'checkbox',
    ));

    $product_hunt_post_meta->add_field(array(
        'name' => '产品链接',
        'id'   => 'product_logo_link',
        'type' => 'text',
    ));

    $product_hunt_post_meta->add_field(array(
        'name' => '产品图片',
        'id'   => 'product_images',
        'type' => 'file_list',
    ));

    $product_hunt_post_meta->add_field(array(
        'name' => '视频链接',
        'id'   => 'product_video',
        'type' => 'text',
    ));


    $product_hunt_post_meta->add_field(array(
        'name' => '投票数量',
        'id'   => 'votes',
        'type' => 'text',
        'default' => 0,
    ));




	//product options page
	$product_hunt_settings = new_cmb2_box(array(
		'id'           => 'b2_normal_product_options_page',
		'tab_title'    => __('产品设置','b2'),
		'object_types' => array( 'options-page' ),
		'option_key'      => 'b2_normal_product',
		'parent_slug'     => 'admin.php?page=b2_normal_main',
		'tab_group'    => 'b2_normal_options',
	));

    $product_hunt_settings->add_field(array(
        'name'    => __( '是否允许用户投稿产品', 'b2' ),
        'id'      => 'product_allow',
        'type'    => 'radio_inline',
        'options' => array(
            1 => __( '允许投稿', 'b2' ),
            0   => __( '禁止投稿', 'b2' ),
        ),
    ));

    //默认投稿的分类ID
    $product_hunt_settings->add_field(array(
        'name'    => __( '限制投稿', 'b2' ),
        'id'      => 'write_can_post_product',
        'type'    => 'text',
        'default'=>3,
        'desc'=>__('普通用户多少篇投稿未审核时不允许再次投稿，管理员，编辑不受此数量限制.（此项设置可以防止垃圾投稿）','b2')
    ));

    //允许投稿的分类
    $product_hunt_settings->add_field(array(
        'name' => __('允许投稿的分类','b2'),
        'id'   => 'write_cats',
        'type' => 'taxonomy_multicheck_hierarchical',
        'taxonomy'=>'category',
        // Optional :
        'text'           => array(
            'no_terms_text' => sprintf(__('没有分类，请前往%s添加','b2'),'<a target="_blank" href="'.admin_url('/edit-tags.php?taxonomy=category').'">分类设置</a>')
        ),
        'remove_default' => 'true', // Removes the default metabox provided by WP core.
        // Optionally override the args sent to the WordPress get_terms function.
        'query_args' => array(
            'orderby' => 'count',
            'hide_empty' => false,
        ),
        'select_all_button' => true,
        'desc'=>__('请确保您的分类别名不是中文，否则无法选中，不选择将不显示分类设置的选项','b2'),
    ));

    //默认投稿的分类ID
    $product_hunt_settings->add_field(array(
        'name'    => __( '默认投稿的分类ID', 'b2' ),
        'id'      => 'write_cats_default',
        'type'    => 'text',
        'desc'=>__('请直接填写分类ID，不设置则默认投入ID为1的分类中','b2')
    ));

    $collection_name = b2_get_option('normal_custom','custom_collection_name');

    //允许投稿的专题
    $product_hunt_settings->add_field(array(
        'name' => sprintf(__('允许投稿的%s','b2'),$collection_name),
        'id'   => 'write_callections',
        'type' => 'taxonomy_multicheck_hierarchical',
        'taxonomy'=>'collection',
        // Optional :
        'text'           => array(
            'no_terms_text' => sprintf(__('没有%s，请前往%s添加','b2'),$collection_name,'<a target="_blank" href="'.admin_url('/edit-tags.php?taxonomy=collection').'">'.$collection_name.'设置</a>')
        ),
        'remove_default' => 'true', // Removes the default metabox provided by WP core.
        // Optionally override the args sent to the WordPress get_terms function.
        'query_args' => array(
            'orderby' => 'count',
            'hide_empty' => false,
        ),
        'select_all_button' => true,
        'desc'=>sprintf(__('请确保您的%s别名不是中文，否则无法选中，不选择将不显示%s设置的选项','b2'),$collection_name,$collection_name),
    ));


    $product_hunt_settings->add_field(array(
        'name'    => sprintf(__( '默认投稿的%sID', 'b2' ),$collection_name),
        'id'      => 'write_callections_default',
        'type'    => 'text',
        'desc'=>sprintf(__('请直接填写%sID','b2'),$collection_name,$collection_name)
    ));
}

add_action('cmb2_admin_init', 'b2_add_product_hunt_post_fields');
